const path = require('path')
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    entry: './src/index.ts',
    output: {
        path: path.resolve(__dirname, '../dist'),
        filename: 'bundle.js',
        clean: true,
    },
    module: {
        rules: [
            {
                //js 文件使用 babel-loader 来处理
                test: /\.(j|t)s$/,
                exclude: /(node_modules)/,
                use: {
                    loader: 'babel-loader'
                }
            },
            // css 和 less 文件按 less-loader、 css-loader、 style-loader的顺序处理，即写在后面的先处理
            {
                test: [/\.css$/, /\.less$/,],
                use: [
                    {
                        loader: 'style-loader',
                        options: {
                            // insert: "body"
                        }
                    },
                    {
                        loader: 'less-loader',
                    },
                ]
            },
            // 图片资源使用 url-loader 处理
            {
                test: [/\.(png|jpe?g|gif|svg)$/],
                loader: 'url-loader',
                options: {
                    // limit: 10000
                }
            },
        ]
    },
    //  plugins 里初始化插件
    plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html',
            filename: 'index.html',
            title: 'MD',
            currentVersion: Math.random(),
            inject: true,
        })
    ],
    resolve: {
        extensions: [".js", ".json", ".wasm", ".ts", ".tsx"],
        alias: {
            "@": path.resolve(__dirname, "../src"),
        },
    },

}

